// pages/mine/mine.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatar: '', //头像
    isIphoneX: false, //是否是iphoneX
    loadModal: true,
    mglist: []
  },
  onShow() {
    var _this = this;
    _this.setData({
      nick_name: wx.getStorageSync('nick_name'),
      avatar: wx.getStorageSync('avatar'),
    })
    //判断iphone x
    wx.getSystemInfo({
      success: res => {
        let modelmes = res.model;
        if (modelmes.search('iPhone X') != -1) {
          _this.setData({
            isIphoneX: true
          })
        }
      }
    })

    //订单数量--待付款
    $api.getOrderNum({
      login_token: wx.getStorageSync('login_token'),
      status: 0
    }).then((res) => {
      _this.setData({
        paymentNum: res.data.data
      })
      //待收货数量
      $api.getOrderNum({
        login_token: wx.getStorageSync('login_token'),
        status: 2
      }).then((res) => {
        _this.setData({
          ReceivingNum: res.data.data,
        })
        //待发货数量
        $api.getOrderNum({
          login_token: wx.getStorageSync('login_token'),
          status: 1
        }).then((res) => {
          _this.setData({
            DeliverNum: res.data.data,
          })
          //退款售后数量
          $api.getOrderNum({
            login_token: wx.getStorageSync('login_token'),
            status: 11
          }).then((res) => {
            _this.setData({
              AfterNum: res.data.data,
              loadModal: false
            })

          }).catch((err) => {
            _this.setData({
              loadModal: false
            })


          })

        }).catch((err) => {
          _this.setData({
            loadModal: false
          })


        })

      }).catch((err) => {
        _this.setData({
          loadModal: false
        })


      })
    }).catch((err) => {
      _this.setData({
        loadModal: false
      })
    })
    $api.getmyconfig({
      login_token: wx.getStorageSync('login_token'),
    }).then((res) => {
      let mglist = []

      res.data.data.forEach((item) => {
        if (item.name == 'wdjf' || item.name == 'hgzq' || item.name == 'gnfk' || item.name == 'hyyy' || item.name == 'czmm' || item.name == 'bdyhm' || item.name == 'wdewm' || item.name == 'smrz'|| item.name== 'gwzd'|| item.name== 'wszl') {
          mglist.push(item)
        }
      })
      _this.setData({
        mglist
      })
    })
    $api.getmyconfignew({
      login_token: wx.getStorageSync('login_token'),
    }).then((res) => {
      let service = []
      let setting = res.data.data.setting
      
      // item.name == 'lxkf'||item.name == 'dzgl' ||发票管理||我的粉丝
      res.data.data.service.forEach((item) => {
        if (item.name == 'wdjf' || item.name == 'hgzq' || item.name == 'gnfk' || item.name == 'hyyy' || item.name == 'czmm' || item.name == 'bdyhm' || item.name == 'wdewm' || item.name == 'smrz'|| item.name== 'gwzd'|| item.name== 'wszl') {
          service.push(item)
        }
      })
      _this.setData({
        service
      })
    })
    
  },
  //修改头像
  onAvatar() {
    var _this = this;
    wx.reLaunch({
      url: '/pages/usercenter/usercenter',
    })
    
  },
  //退出账号
  onOutAccount() {
    wx.showModal({
      title: '提示',
      content: '您确定要退出吗？',
      success(res) {
        if (res.confirm) {
          wx.clearStorageSync();
          wx.reLaunch({
            url: '/pages/login/pass/pass',
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },
  //进入首页
  onIndex() {
    wx.reLaunch({
      url: '/pages/index/index',
    })
  },
  //进入首页home
  onhome() {
    wx.reLaunch({
      url: '/pages/home/home',
    })
  },
  //进入商品列表
  ongoodslist() {
    wx.reLaunch({
      url: '/pages/goodslist/goodslist',
    })
  },
  //查看订单
  onOrder(e) {
    wx.navigateTo({
      url: '/pages/order/order?type=' + e.currentTarget.dataset.type,
    })
  },
  //进入售后列表
  onSaleList() {
    wx.navigateTo({
      url: '/pages/sale/list/list',
    })
  },
  //进入我的积分
  onIntegral() {
    wx.navigateTo({
      url: '/pages/integral/integral',
    })
  },
  // 进入直播
  onlive() {
    wx.reLaunch({
      url: '/pages/live/live',
    })
  },
  //进入换购专区
  onReplacement() {
    wx.navigateTo({
      url: '/pages/replacement/replacement',
    })
  },
  // 回馈意见
  onfeedback() {
    wx.navigateTo({
      url: '/pages/feedback/feedback',
    })
  },
  onInMeeting() {
    wx.navigateTo({
      url: '/pages/Meetinginvitation/Meetinginvitation',
    })
  },
  onUp(e) {
    let _this = this
    let name = e.currentTarget.dataset.name
    if (name == 'wdjf') {
      _this.onIntegral()
    }
    if (name == 'hgzq') {
      _this.onReplacement()
    }
    if (name == 'gnfk') {
      _this.onfeedback()
    }
    if (name == 'hyyy') {
      _this.onInMeeting()
    }
    if (name == 'czmm') {
      _this.onrpd()
    }
    if (name == 'wdewm') {
      _this.onwdewm()
    }
    if (name == 'bdyhm') {
      _this.onbdyhm()
    }
    if (name == 'smrz') {
      _this.onsmrz()
    }
    if (name == 'gwzd') {
      _this.ongwzd()
    }
    if (name == 'wszl') {
      // _this.ongwzd()
      wx.navigateTo({
        url: '/pages/reading/reading?wszl=1&&state=2&&informationState=2',
      })
    }
  },
  ongwzd(){
    wx.navigateTo({
      url: '/pages/consultant/consultant',
    })
  },
  onrpd() {
    wx.navigateTo({
      url: '/pages/resetpassword/resetpassword',
    })
  },
  onwdewm() {
    wx.navigateTo({
      url: '/pages/invitation/invitation',
    })
  },
  onbdyhm() {
    wx.navigateTo({
      url: '/pages/bindcoupon/bindcoupon',
    })
  },
  onsmrz() {
    wx.navigateTo({
      url: '/pages/Payment/Payment?lookType=3',
    })
  },
})